<?php


namespace App\Models;


use App\Traits\DateTimeModel;
use App\Traits\Model\OrderByIdDesc;
use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    use OrderByIdDesc, DateTimeModel;

    protected $fillable = ['unique', 'customer_id', 'sku',
        'barcode', 'name', 'net_weight', 'weight', 'brand',
        'hs_code', 'country', 'unit', 'currency', 'element',
        'qy1', 'qy2', 'model', 'specs', 'function', 'use', 'ingredient', 'status'];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     * @author luffyzhao@vip.126.com
     */
    public function images(){
        return $this->hasMany(ProductImage::class);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     * @author luffyzhao@vip.126.com
     */
    public function logs(){
        return $this->hasMany(ProductLog::class);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function hsCodeModel(){
        return $this->belongsTo(HsCode::class, 'hs_code');
    }

    /**
     * @return bool
     */
    public function canUpdate(){
        return $this->getAttribute('status') === 0 || $this->getAttribute('status') === 2;
    }

    /**
     * @return bool
     */
    public function canExamine(){
        return $this->getAttribute('status') === 1;
    }

    /**
     * @return bool
     */
    public function isLock(){
        return $this->getAttribute('status') === 4;
    }

    /**
     * 是否正常
     * @return bool
     */
    public function isNormal(){
        return $this->canFrozen();
    }

    /**
     * @return bool
     */
    public function canFrozen(){
        return $this->getAttribute('status') === 3;
    }
}
